using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace SrWinGui
{
    public partial class frmRipping : Form
    {
        private Ripper rp;
        public frmRipping()
        {
            InitializeComponent();
            rp = Ripper.Instance;
        }
        
        //overloaded show for ripping from station lists
        public void Show(string id)
        {            
            this.Show();
            Thread t = new Thread(rp.DownloadStationInfo);
            t.Start(id);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Ripper r = Ripper.Instance;
            updateListview();
            lblServer.Text = r.Stream;
            lblBitrate.Text = r.Bitrate;
            lblMeta.Text = r.MetaInterval;
            lblArguments.Text = Impostazioni.Instance.GetArguments();
        }

        private void updateListview()
        {
            lstSongList.Items.Clear();
            DataTable dt = rp.SongsTable;
            
            int numRows = dt.Rows.Count;
            for (int i = 0; i < numRows; i++)
            {
                ListViewItem lvi = new ListViewItem(new string[] { dt.Rows[i]["Title"].ToString(), dt.Rows[i]["Size"].ToString(), dt.Rows[i]["Status"].ToString() });
                lstSongList.Items.Add(lvi);
            }

        }

        private void uxRecord_Click(object sender, EventArgs e)
        {
            rp.StartRipping(txtUrl.Text);
        }

        private void uxStop_Click(object sender, EventArgs e)
        {
            Ripper.Instance.KillRipping();
        }
    }
}

